package com.zmhc.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zmhc.common.log.annotation.Log;
import com.zmhc.common.log.enums.BusinessType;
import com.zmhc.common.security.annotation.RequiresPermissions;
import com.zmhc.product.domain.Parameters;
import com.zmhc.product.service.IParametersService;
import com.zmhc.common.core.web.controller.BaseController;
import com.zmhc.common.core.web.domain.AjaxResult;
import com.zmhc.common.core.utils.poi.ExcelUtil;
import com.zmhc.common.core.web.page.TableDataInfo;

/**
 * 商品参数Controller
 * 
 * @author ruoyi
 * @date 2023-12-11
 */
@RestController
@RequestMapping("/parameters")
public class ParametersController extends BaseController
{
    @Autowired
    private IParametersService parametersService;

    /**
     * 查询商品参数列表
     */
    @RequiresPermissions("product:parameters:list")
    @GetMapping("/list")
    public TableDataInfo list(Parameters parameters)
    {
        startPage();
        List<Parameters> list = parametersService.selectParametersList(parameters);
        return getDataTable(list);
    }

    /**
     * 导出商品参数列表
     */
    @RequiresPermissions("product:parameters:export")
    @Log(title = "商品参数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Parameters parameters)
    {
        List<Parameters> list = parametersService.selectParametersList(parameters);
        ExcelUtil<Parameters> util = new ExcelUtil<Parameters>(Parameters.class);
        util.exportExcel(response, list, "商品参数数据");
    }

    /**
     * 获取商品参数详细信息
     */
    @RequiresPermissions("product:parameters:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(parametersService.selectParametersById(id));
    }

    /**
     * 新增商品参数
     */
    @RequiresPermissions("product:parameters:add")
    @Log(title = "商品参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Parameters parameters)
    {
        return toAjax(parametersService.insertParameters(parameters));
    }

    /**
     * 修改商品参数
     */
    @RequiresPermissions("product:parameters:edit")
    @Log(title = "商品参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Parameters parameters)
    {
        return toAjax(parametersService.updateParameters(parameters));
    }

    /**
     * 删除商品参数
     */
    @RequiresPermissions("product:parameters:remove")
    @Log(title = "商品参数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(parametersService.deleteParametersByIds(ids));
    }
}
